//
//  ContactTableViewCell.m
//  CareGiver
//
//  Created by Guillermo Moral on 9/3/14.
//  Copyright (c) 2014 Humana. All rights reserved.
//

#import "ContactTableViewCell.h"
#import <MapKit/MapKit.h>

@implementation ContactTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)pressShareButton:(id)sender {
    
    [_delegate pressShareButtonWithCell:self];
    
}

-(void)configAddress:(NSString*)address city:(NSString*)city {
    NSString *firstLine = [NSString stringWithFormat:@"%@ \n",address];
    NSMutableAttributedString* str1 = [[NSMutableAttributedString alloc] initWithString:firstLine];
    
    NSMutableAttributedString* str2 = [[NSMutableAttributedString alloc] initWithString:city];
    
    [[self.addressView textStorage]appendAttributedString:str1];
    [[self.addressView textStorage]appendAttributedString:str2];
}


+(NSString*)cellIdentifier {
    return @"contactCell";
}

- (IBAction)openMap:(id)sender {
    
    NSString *location = @"242 E Main St, Louisville, KY 40202";
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:location
                 completionHandler:^(NSArray* placemarks, NSError* error){
                     if (placemarks && placemarks.count > 0) {
                         CLPlacemark *topResult = [placemarks objectAtIndex:0];
                         MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
                         
                         Class mapItemClass = [MKMapItem class];
                         if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
                         {
                          
                             MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
                             //[mapItem setName:@"My Place"];
                             // Pass the map item to the Maps app
                             [mapItem openInMapsWithLaunchOptions:nil];
                         }
                         
                         
                     }
                 }
     ];
}
@end
